//package org.dromara.web.mock;
//
//import cn.dev33.satoken.oauth2.exception.SaOAuth2Exception;
//import cn.dev33.satoken.oauth2.granttype.handler.PasswordGrantTypeHandler;
//import cn.dev33.satoken.oauth2.granttype.handler.model.PasswordAuthResult;
//import cn.hutool.core.util.ObjectUtil;
//import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
//import lombok.RequiredArgsConstructor;
//import org.dromara.common.core.constant.SystemConstants;
//import org.dromara.common.core.exception.user.UserException;
//import org.dromara.system.domain.SysUser;
//import org.dromara.system.domain.vo.SysUserVo;
//import org.dromara.system.mapper.SysUserMapper;
//import org.springframework.stereotype.Component;
//
///**
// * 自定义 Password Grant_Type 授权模式处理器认证过程
// *
// * @author click33
// * @since 2025/5/11
// */
//@Component
//@RequiredArgsConstructor
//public class CustomPasswordGrantTypeHandler extends PasswordGrantTypeHandler {
//
//    private final SysUserMapper userMapper;
//    @Override
//    public PasswordAuthResult loginByUsernamePassword(String username, String password) {
//
//        SysUserVo user = loadUserByUsername(username);
//        long userId = user.getUserId();
//        return new PasswordAuthResult(userId);
//    }
//
//    private SysUserVo loadUserByUsername(String username) {
//        SysUserVo user = userMapper.selectVoOne(new LambdaQueryWrapper<SysUser>().eq(SysUser::getUserName, username));
//        if (ObjectUtil.isNull(user)) {
//            throw new UserException("user.not.exists", username);
//        } else if (SystemConstants.DISABLE.equals(user.getStatus())) {
//            throw new UserException("user.blocked", username);
//        }
//        return user;
//    }
//}
